package j20251122;
// 组件接口
interface Coffee {
    double getCost();
    String getDescription();
}
// 具体组件
class SimpleCoffee implements Coffee {
    @Override
    public double getCost() { return 1.0; }
    @Override
    public String getDescription() { return "Simple coffee"; }
}
// 装饰器抽象类
abstract class CoffeeDecorator implements Coffee {
    protected Coffee decoratedCoffee;
    public CoffeeDecorator(Coffee coffee) {
        this.decoratedCoffee = coffee;
    }
    @Override
    public double getCost() {
        return decoratedCoffee.getCost();
    }
    @Override
    public String getDescription() {
        return decoratedCoffee.getDescription();
    }
}
// 具体装饰器
class MilkDecorator extends CoffeeDecorator {
    public MilkDecorator(Coffee coffee) {
        super(coffee);
    }
    @Override
    public double getCost() {
        return super.getCost() + 0.5;
    }
    @Override
    public String getDescription() {
        return super.getDescription() + ", Milk";
    }
}
public class Demo2 {
    public static void main(String[] args) {
        // 使用
        Coffee coffee = new MilkDecorator(new SimpleCoffee());
        System.out.println(coffee.getDescription() + " $" + coffee.getCost());
    }
}
